package com.levy.contronller.javaWeb.pdfTest;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * Created by levy on 2019/4/23.
 */
public class PdfToPngTest {

    public static void main(String[] args) throws IOException {
        File file = new File("G:\\pdf\\11.pdf");
        try {
            PDDocument doc = PDDocument.load(file);
            PDFRenderer renderer = new PDFRenderer(doc);
            int pageCount = doc.getNumberOfPages();
            for (int i = 0; i < pageCount; i++) {
                BufferedImage image = renderer.renderImageWithDPI(i, 296);
//          BufferedImage image = renderer.renderImage(i, 2.5f);
                ImageIO.write(image, "PNG", new File("G:\\pdf\\pdfbox_image_"+i+".png"));
                System.out.println(i+"_over");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
